#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <dirent.h>
#include <sys/stat.h>

using namespace std;

void FindFile (const string& file, const string& folder)
{
	static DIR *directory;
	static struct dirent *actual_directory;
	static bool exit;	
	if( (directory = opendir (folder.c_str())) == NULL )
		return;

	vector<string> folders;
	while ((actual_directory = readdir (directory)) != NULL) {
		if ((string (actual_directory->d_name) == "." || string (actual_directory->d_name) == "..") ||  S_ISLNK(DTTOIF(actual_directory->d_type)))
              continue; //Trouble with direct access loops right here
		string chain = folder + '/' + actual_directory->d_name;
		struct stat structure;

		if (stat (chain.c_str(), &structure) < 0)
		{
			;//Don't do nothing
	    }
		else if (S_ISDIR (structure.st_mode)&&!(S_ISLNK(structure.st_mode))) //Check if file is a directory
		{   
		    if( file == actual_directory->d_name )
		    {  
		        cout << '[' << chain << ']' << endl;
                //exit = true;
		    }
			folders.push_back (actual_directory->d_name);
		}
	    else if (file == actual_directory->d_name)
		{
			cout << '[' << chain << ']' << endl;
            //exit = true;
		}
	}
	closedir (directory);

	for (int i = 0; i < folders.size(); ++i){
		FindFile (file, folder + '/' + folders[i]);
        /*if(exit == true){
            break;
        }*/
    }
}

int main ( int argc, char *argv[] )
{
	FindFile (argv[1],argv[2]);
	return 0;
}
